/** 当收到请求回复时候回调  **/
function onReplyReceived(reply)
{
  console.log(reply);
  if(reply.key=="client_bind"){
    var user = JSON.parse(reply.data.body);
    $("#nowusers_count").html(user.length);
    $("#user_list").html("");
    for(var kk in  user){
      if(user[kk].user != $("#inp_nickname").val()){
        var html = '<a id="userid_'+user[kk].channl+'" class="list-group-item" onclick="sendPersion(this)" style="color:black" ><span class="badge"></span><span style="margin-right:5px;" class="glyphicon glyphicon-user"></span><span class="nickname">'+user[kk].user+'</span></a>'
        $("#user_list").append(html);
      }
    }
  }else if(reply.key == "client_closed"){
    var user = JSON.parse(reply.data.body);
    $("#nowusers_count").html(user.length);
    $("#user_list").html("");
    for(var kk in  user){
      if(user[kk].user != $("#inp_nickname").val()){
        var html = '<a id="userid_'+user[kk].channl+'" class="list-group-item" onclick="sendPersion(this)" style="color:black" ><span class="badge"></span><span style="margin-right:5px;" class="glyphicon glyphicon-user"></span><span class="nickname">'+user[kk].user+'</span></a>'
        $("#user_list").append(html);
      }
    }
  }else {
    var message = JSON.parse(reply.data.body);
    time = jutils.formatDate(new Date(message.timestamp),"YYYY-MM-DD HH:ii:ss")
    //回复者id
    var html =  '<div class="chat-message chat-message-left">'+
                '  <div class="chat-message-text">'+
                '    <span>'+message.content+'</span>'+
                '  </div>'+
                '  <div class="chat-message-meta">'+
                '    <span>'+time+'<i class="feather icon-check ml-2"></i></span>'+
                '  </div>'+
                '</div>';
    //添加消息
    $("#chat-"+message.sender).append(html);
    $("#chat-"+message.sender+" .empty-screen").hide();
  }
}


//发送消息
function sendMessage(message){
  var body = {
    "action": "txt",
    "content": message,
    "extra": "string",
    "receiver": receiverId,
    "sender": userId
  }
  fun_loading(!0)
  http.post({url:serverUrl+'send',data:body},function(err,result){
    if(result.code == 0){
      time = jutils.formatDate(new Date(body.timestamp),"YYYY-MM-DD HH:ii:ss")
      var html =  '<div class="chat-message chat-message-right">'+
          '  <div class="chat-message-text">'+
          '    <span>'+body.content+'</span>'+
          '  </div>'+
          '  <div class="chat-message-meta">'+
          '    <span>'+time+'<i class="feather icon-check ml-2"></i></span>'+
          '  </div>'+
          '</div>';
      //添加消息
      $("#chat-"+body.receiver).append(html);
      $("#chat-"+body.receiver+" .empty-screen").hide();
    }else{
      layer.msg(result.msg);
      getimgcode();
    }
    fun_loading(!1)
  });
}